package com.pbq.pickerlib;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.pbq.pickerlib.wheel.BankWheelManagerBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Ani_aierJun on 2017/10/19.
 */

public class TestSample {
    private List<BankInfoEntity> banklst = new ArrayList<>();
    private PopupWindow mBankWindow;
    private WheelTextSelector mBankWheelTextSelector;
    private Bundle mBankBundle = new Bundle();
    private List<String> mBankResult = new ArrayList<>();
    private List<String> mList = new ArrayList<>();
    private String bankid; //选择的银行id
    private TextView credit_bank;

    public void test(Context context){
        mBankWheelTextSelector = new WheelTextSelector(context, mBankBundle);
        mList.clear();
        for (int i = 0; i < banklst.size(); i++) {
            mList.add(banklst.get(i).getBk_name());
        }

        mBankWindow = mBankWheelTextSelector.
                makePopupWindow("请选择银行", BankWheelManagerBuilder.getInstance().build(context, mList));//用于显示的mList

        if (null != mBankWindow)
            mBankWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    mBankResult = mBankBundle.getStringArrayList(WheelTextSelector.WHEEL_RESULT);//mBankResult得到回调的string
                    if (mBankResult != null) {
                        credit_bank.setText(mBankResult.get(0));
                        credit_bank.setTextColor(Color.parseColor("#000000"));

                        for (int i = 0; i < banklst.size(); i++) {
                            if (mBankResult.get(0).equals(banklst.get(i).getBk_name())) {
                                bankid = banklst.get(i).getBk_id();
                                break;
                            }
                            ;
                        }
                    }
                }
            });
    }

    public void show(View parentView){//父view.例如：点击的view（LinearLayout等）
        if (null != mBankWindow)
            mBankWindow.showAtLocation(parentView, Gravity.BOTTOM, 0, 0);
    }


}
